
<template>
	<view>
		<view v-if="loading">
			<loading></loading>
		</view>
		<view  class="container"  v-else>
			<view class="topTitle">
				<text @tap="toLog">观看记录</text>
			</view>
			<view class="grid-body">
				<uni-grid :column="count" :showBorder="false" >
					<uni-grid-item v-for="(item,index) in workList" :index="index" :key="index" class="gridView">
						<view class="grid-item-box" @click="clickGridItem(item)">
							<view class="imgView" ><image :src="item.photoUrl"></image></view>
							<text class="text">{{item.categoryName}}</text>
						</view>
					</uni-grid-item>
				</uni-grid>
			</view>
			<view class="course-body">
				<view class="course-view"  v-for="(item,index) in list" :index="index" :key="index"   @click="clickDetail(item)">
					<view class="imgView">
						<image :src="item.imgUrl" mode="heightFix"></image>
					</view>
					<view class="textView">
						<text>{{item.knowledgeName}}</text>
					</view>
				</view>
				<view class="load-more">
					<uni-icons v-if="loadShow" type="spinner-cycle" size="30"></uni-icons>
					<text  v-if="botShow">已经到底了</text>
				</view>
			</view>
		</view>
		
			<show-modal></show-modal>
	</view>

</template>


<script>
	import loading from '@/components/loading/loading'
	import { getCourseList,getCate } from '@/api/exam/activity'
	export default {
		data() {
			return {
			pageForm:{
				pageNo:1,
				pageSize:10
				
			}	,
			workList:[
				
			],
			list:[],
			loadShow:false,
			botShow:false,
			loading:true,
			count:5
			}
		},
		created(){
			this.getList()
			this.getCateList()
		},
		onReachBottom(){
			if(!this.botShow){
				this.loadShow = true
				this.pageForm.pageNo ++ ;
				this.getList()
			}
			
		},
		methods: {
			getList(){
				getCourseList(this.pageForm).then(res =>{
					
					if(res.data.list.length > 0){
						this.list.push(...res.data.list)
						this.loadShow = false
					}else{
						this.loadShow = false
						this.botShow = true
					}
					this.loading = false
				})
			},
			
			getCateList(){
				let data = {
					status:0,
					parentId:0
				}
				getCate(data).then(res =>{
					this.workList = res.data
					if(res.data.length>5){
						this.count = 5
					}else{
						this.count = res.data.length
					}
					
				})
			},
			clickGridItem(e) {
				this.$tab.navigateTo('/pages/course/course?categoryId=' + e.id)
			},
			toLog(){
				this.$tab.navigateTo('/pages/course/courseLog')
			},
			clickDetail(e){
				this.$tab.navigateTo('/pages/course/courseDetail?courseId=' + e.id)
			}
		}
	}
</script>

<style lang="scss">
	.container{
		width: calc(100vw - 60rpx);
		margin: 0 auto;
	}
	.topTitle{
		display: flex;
		flex-direction: row-reverse;
		padding: 18rpx;
		
	}
	.grid-body{
		background-color: #fff;
		box-shadow: 0rpx 4rpx 60rpx 10rpx rgba(156,193,220,0.25);
		border-radius: 20rpx;
		padding: 40rpx 0;
		.gridView {
			font-size: 24rpx;
			.grid-item-box {
					flex: 1;
					/* #ifndef APP-NVUE */
					display: flex;
					/* #endif */
					flex-direction: column;
					align-items: center;
					justify-content: center;
					.imgView{
						box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.25);
						width: 100rpx;
						height: 100rpx;
						background: #FF9A50;
						border-radius: 20rpx;
						/* #ifndef APP-NVUE */
						display: flex;
						/* #endif */
						flex-direction: column;
						align-items: center;
						justify-content: center;
						image{
							width: 60rpx;
							height: 60rpx;
						}
					}
					.text{
						line-height: 60rpx;
						color: #5E5E5E;
					}
				}
			}
		}
	.course-body{
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		border-radius: 20rpx;
		.course-view{
			background-color: #fff;
			margin-top: 40rpx;
			border-radius: 10rpx;
			box-shadow: 0px 2px 34px 5px rgba(156,193,220,0.25);
			overflow: hidden;
			.imgView{
				width: 320rpx;
				height: 300rpx;
				image{
					height: auto;
					height: 300rpx;
				}
			}
			.textView{
				width: 320rpx;
				height: 88rpx;
				background-color: #fff;
				display: block;
				text-align: center;
				line-height: 88rpx;
				overflow: hidden;
			}
		}
	}
	.load-more{
		display: block;
		padding: 20px;
		margin: 0 auto;
	}
</style>